﻿CREATE TRIGGER t_Menu_Lable
ON dbo.t_Menu
FOR UPDATE, DELETE
AS
IF NOT UPDATE (MenuLable) RETURN

DECLARE @Objects nvarchar(4000),@SQL nvarchar(4000)
SELECT @SQL = 'select ''[''+name+'']'' from sys.all_objects WHERE name like ''%[_]'+MenuLable+'''' FROM deleted
EXEC sp__Join @SQL,',',@Objects OUTPUT

IF ISNULL(@Objects,'') = '' RETURN

ROLLBACK TRAN
RAISERROR('%s object(s) reference this menu.',16,1,@Objects)


